﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using Microsoft.Phone.Net.NetworkInformation;

namespace myChannel9
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();

            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                MessageBox.Show("No internet connection is available.  Try again later.");
            }
   
            controlNews.goToVideoInfo += new EventHandler(control_goToVideo);
            controlSeries.goToSeries += new EventHandler(controlShow_goToShow);
            controlShow.goToShow += new EventHandler(controlShow_goToShow);
            controlSearch.goToVideoInfo += new EventHandler(control_goToVideo);
            controlTags.goToTags += new EventHandler(controlTags_goToTags);
            controlFavorites.goToVideoInfo += new EventHandler(control_goToVideo);

            controlNews.loadNews();
            controlFavorites.loadFavorites();
        }

        void controlTags_goToTags(object sender, EventArgs e)
        {
            TagObject tag = sender as TagObject;
            this.NavigationService.Navigate(new Uri("/Tags.xaml", UriKind.Relative));
        }

        void controlShow_goToShow(object sender, EventArgs e)
        {
            ShowObject show = sender as ShowObject;
            this.NavigationService.Navigate(new Uri("/Show.xaml", UriKind.Relative));
        }

        void control_goToVideo(object sender, EventArgs e)
        {
            VideoObject video = sender as VideoObject;
            this.NavigationService.Navigate(new Uri("/VideoInfo.xaml", UriKind.Relative));
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            controlFavorites.loadFavorites();
        }

        private void btnSettings_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
        }

        private void btnRefresh_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            controlNews.loadNews();
        }
    }
}
